package menuitems;

import gui.MainWindow;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;

public class MainMenuBar extends JMenuBar implements ActionListener {
	
	//Variables used by the menubar
	private MainWindow mainwindow;
	
	private JMenu menuFile;
	private JMenu menuConfigure;
	private JMenu menuRaces;
	private JMenu menuFilter;
	//private JMenu menuProfession;
	
	private JMenuItem mSave, mNew, mDelete, mImportFromArmory, mRename;

	public MainMenuBar(MainWindow mainwindow) {
		setMainWindow(mainwindow);
		menuFile = new JMenu("File");
		
	}
	
	protected void createFileMenu() {
		menuFile.removeAll(); // preparing for startup for the items to be added.
		
		//Setting upp all the different items for this profile
		mNew = new JMenuItem("New profile");
		mNew.addActionListener(this);
		menuFile.add(mNew);
		
		mSave = new JMenuItem("Save profile");
		mSave.addActionListener(this);
		menuFile.add(mSave);
		
		mDelete = new JMenuItem("Delete profile");
		mDelete.addActionListener(this);
		menuFile.add(mDelete);
		
		mRename = new JMenuItem("Rename profile");
		mRename.addActionListener(this);
		menuFile.add(mRename);
		
		menuFile.addSeparator();
		
		mImportFromArmory = new JMenuItem("Import existing profile");
		mImportFromArmory.addActionListener(this);
		menuFile.add(mImportFromArmory);
		
		menuFile.addSeparator();
		
	}
	
	/**
	 * @param ActionEvent 
	 * This class is used by the various menuFile-JMenuItems.
	 * To be used as a common method!!
	 */
	@Override
	public void actionPerformed(ActionEvent e) {
		MenuItemChosen chosenItem;
		
		if(e.getSource().equals(mNew)) chosenItem = MenuItemChosen.NEW;
		else if (e.getSource().equals(mDelete)) chosenItem = MenuItemChosen.DELETE;
		else if (e.getSource().equals(mRename)) chosenItem = MenuItemChosen.RENAME;
		else if (e.getSource().equals(mSave)) chosenItem = MenuItemChosen.SAVE;
		else if (e.getSource().equals(mImportFromArmory)) chosenItem = MenuItemChosen.IMPORTARMORY;
		else chosenItem = MenuItemChosen.NEW;
		
		switch (chosenItem) {
		case NEW:
			break;
		case DELETE:
			int confirmDeleteDialog = JOptionPane.showConfirmDialog(getMainWindow(), 
					"Are you sure you'd like to delete \r\n this profile?", 
					"Confirm deletion of profile.", JOptionPane.YES_NO_OPTION);
			if(confirmDeleteDialog == JOptionPane.OK_OPTION) {
				//User clicked sure, wtf I dont care - delete this fucker!!
				
				createFileMenu();
				
			}
			break;
		case RENAME:
			break;
		case SAVE:
			break;
		case IMPORTARMORY:
			break;
		}
	}
	

	public MainWindow getMainWindow() {
		return this.mainwindow;
	}

	public void setMainWindow(MainWindow mainwindow) {
		this.mainwindow = mainwindow;
	}

}
